package cn.bugstack.mybatis.mapping;

import javax.sql.DataSource;

import cn.bugstack.mybatis.transaction.TransactionFactory;

/**
 * description: 环境配置
 * taskId：
 * <pre>
 * change history:
 * date             defect#             person                comments
 * ---------------------------------------------------------------------
 * 2024/11/27       ********         zhaochaoyue        create file
 * </pre>
 *
 * @author: zhaochaoyue
 * @date: 2024/11/27 14:51
 * @copyright: 2024
 */
public final class Enviornment {
    
    // 环境id
    private final String id;
    // 事物工厂
    private final TransactionFactory transactionFactory;
    // 数据源
    
    private final DataSource dataSource;

    public Enviornment(String id, TransactionFactory transactionFactory, DataSource dataSource) {
        this.id = id;
        this.transactionFactory = transactionFactory;
        this.dataSource = dataSource;
    }
    
    public static class Builder{
        private String id;
        
        private TransactionFactory transactionFactory;
        
        private DataSource dataSource;

        public Builder(String id) {
            this.id = id;
        }

        public Builder transactionFactory(TransactionFactory transactionFactory) {
            this.transactionFactory = transactionFactory;
            return this;
        }

        public Builder dataSource(DataSource dataSource) {
            this.dataSource = dataSource;
            return this;
        }
        
        public String id(){
            return this.id;
        }
        
        public Enviornment build(){
            return new Enviornment(this.id,this.transactionFactory,this.dataSource);
        }
    }

    public String getId() {
        return id;
    }

    public TransactionFactory getTransactionFactory() {
        return transactionFactory;
    }

    public DataSource getDataSource() {
        return dataSource;
    }
}
